function HtmlEncode(_input){

function hex(){
var h = 0;
if (hex.arguments.length == 1)
{
h = hex.arguments[0] & 0xF;
h = (h <= 9 ? h + 48 : h + 55);
}
else if (hex.arguments.length > 1)
{
h = (hex.arguments[1] >> (4 * hex.arguments[0])) & 0xF;
h = (h <= 9 ? h + 48 : h + 55);
}
return h;
};
var result = new Array();
var _HS = false;
var _r = 0x0;
for (var _i = 0; _i < _input.length; _i++) {
var _x = _input.charCodeAt(_i);
if (!_HS){
if (String.fromCharCode(_x).match(/^([\x20\x21\x23-\x25\x28-\x3B\x3D\x3F-\x7E\xA1-\xAC\xAE-\u036F])$/)){
result.push(String.fromCharCode(_x));
}
else {
if ((_x == 0x22)){
result.push(String.fromCharCode(0x26, 0x71, 0x75, 0x6F, 0x74, 0x3B));
}
else {
if ((_x == 0x26)){
result.push(String.fromCharCode(0x26, 0x61, 0x6D, 0x70, 0x3B));
}
else {
if ((_x == 0x3C)){
result.push(String.fromCharCode(0x26, 0x6C, 0x74, 0x3B));
}
else {
if ((_x == 0x3E)){
result.push(String.fromCharCode(0x26, 0x67, 0x74, 0x3B));
}
else {
if ((_x < 0x10)){
result.push(String.fromCharCode(0x26, 0x23, 0x58, hex(0x0,_x), 0x3B));
}
else {
if ((_x < 0x100)){
result.push(String.fromCharCode(0x26, 0x23, 0x58, hex(0x1,_x), hex(0x0,_x), 0x3B));
}
else {
if ((_x < 0x1000)){
result.push(String.fromCharCode(0x26, 0x23, 0x58, hex(0x2,_x), hex(0x1,_x), hex(0x0,_x), 0x3B));
}
else {
if (((0xD800 <= _x) && (_x <= 0xDBFF))){
if ((((_x >> 0x6) & 0xF) == 0xF)){
result.push(String.fromCharCode(0x26, 0x23, 0x58, 0x31, 0x30, hex(0x0,(_x >> 0x2))));
_HS = true;
_r = (_x & 0x3);
}
else {
result.push(String.fromCharCode(0x26, 0x23, 0x58, hex(0x0,((_x >> 0x6) + 0x1)), hex(0x0,(_x >> 0x2))));
_HS = true;
_r = (_x & 0x3);
}
}
else {
if ((((0xDC00 <= _x) && (_x <= 0xDFFF)) || (_x == 0xFFFF) || (_x == 0xFFFE))){
throw {name:'InvalidInput'};
}
else {
result.push(String.fromCharCode(0x26, 0x23, 0x58, hex(0x3,_x), hex(0x2,_x), hex(0x1,_x), hex(0x0,_x), 0x3B));
}
}
}
}
}
}
}
}
}
}
}
else if (true){
if (((0xDC00 <= _x) && (_x <= 0xDFFF))){
result.push(String.fromCharCode(hex(((_r << 0x2) | ((_x >> 0x8) & 0x3))), hex(0x1,_x), hex(0x0,_x), 0x3B));
_HS = false;
_r = 0x0;
}
else {
throw {name:'InvalidInput'};
}
}
}
if (_HS){
throw {name:'InvalidInput'};
}
return result.join('');
}
